'use strict';
/**
 * @name: node封装mysql
 * @description: 针对于框架进行了封装
 * @version: 0.0.1
 * @author: xiech
 * @Date: 2020-12-10 13:53:30
 * @LastEditors: xiech
 * @LastEditTime: 2020-12-10 13:53:30
 */

module.exports = async (ctx) => {
  const mysqldb = ctx.cloud.dataspace;
  if(!mysqldb) return;
  const mfmysqldb = {};
  /**
   * @description: 自定义sql
   * @param {string} sql 
   * @param {object[]} params 数据
   * @return {object} 自定义sql返回值
   */
  mfmysqldb.query = async (sql, params = []) => {
    return new Promise((resolve,reject) => {
      mysqldb.query(sql, params, (err, result) => {
        if(err){
          reject(err);
        }else{
          resolve(result);
        }
      });
    });
  };
  return mfmysqldb;
}